﻿#include "jitems.h"
#include <QDebug>

JItems::JItems()
{

}

/**
 * Sample implementation of the method which handles layers.
 */
void JItems::addLayer(const DL_LayerData& data)
{
    qDebug("LAYER: %s flags: %d", data.name.c_str(), data.flags);
    printAttributes();
}

/**
 * Sample implementation of the method which handles point entities.
 */
void JItems::addPoint(const DL_PointData& data)
{
    qDebug("POINT    (%6.3f, %6.3f, %6.3f)",
           data.x, data.y, data.z);
    printAttributes();
}

/**
 * Sample implementation of the method which handles line entities.
 */
void JItems::addLine(const DL_LineData& data)
{
    qDebug("LINE     (%6.3f, %6.3f, %6.3f) (%6.3f, %6.3f, %6.3f)",
           data.x1, data.y1, data.z1, data.x2, data.y2, data.z2);
    printAttributes();
}

/**
 * Sample implementation of the method which handles arc entities.
 */
void JItems::addArc(const DL_ArcData& data)
{
    qDebug("ARC      (%6.3f, %6.3f, %6.3f) %6.3f, %6.3f, %6.3f",
           data.cx, data.cy, data.cz,
           data.radius, data.angle1, data.angle2);
    printAttributes();
}

/**
 * Sample implementation of the method which handles circle entities.
 */
void JItems::addCircle(const DL_CircleData& data)
{
    qDebug("CIRCLE   (%6.3f, %6.3f, %6.3f) %6.3f",
           data.cx, data.cy, data.cz,
           data.radius);
    printAttributes();
}


/**
 * Sample implementation of the method which handles polyline entities.
 */
void JItems::addPolyline(const DL_PolylineData& data)
{
    qDebug("POLYLINE ");
    qDebug("flags: %d", static_cast<int>(data.flags));
    printAttributes();
}


/**
 * Sample implementation of the method which handles vertices.
 */
void JItems::addVertex(const DL_VertexData& data)
{
    qDebug("VERTEX   (%6.3f, %6.3f, %6.3f) %6.3f",
           data.x, data.y, data.z,
           data.bulge);
    printAttributes();
}


void JItems::add3dFace(const DL_3dFaceData& data)
{
    qDebug("3DFACE");
    for (int i=0; i<4; i++) {
        qDebug("   corner %d: %6.3f %6.3f %6.3f",
            i, data.x[i], data.y[i], data.z[i]);
    }
    printAttributes();
}

void JItems::printAttributes()
{
    qDebug("  Attributes: Layer: %s, ", attributes.getLayer().c_str());
    qDebug(" Color: ");
    if (attributes.getColor()==256)	{
        qDebug("BYLAYER");
    } else if (attributes.getColor()==0) {
        qDebug("BYBLOCK");
    } else {
        qDebug("%d", attributes.getColor());
    }
    qDebug(" Width: ");
    if (attributes.getWidth()==-1) {
        qDebug("BYLAYER");
    } else if (attributes.getWidth()==-2) {
        qDebug("BYBLOCK");
    } else if (attributes.getWidth()==-3) {
        qDebug("DEFAULT");
    } else {
        qDebug("%d", attributes.getWidth());
    }
    qDebug(" Type: %s", attributes.getLinetype().c_str());
}
